ROOT    = .
SDKROOT = $(ROOT)/..
WORKTOOLS       = $(SDKROOT)/workspace/pctools
TOOLCHAIN=/home/sniper/work/a10/toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf
TCHAIN_PREFIX = /bin/arm-linux-gnueabihf-

#编译器
CC          = $(TOOLCHAIN)$(TCHAIN_PREFIX)gcc
CXX         = $(TOOLCHAIN)$(TCHAIN_PREFIX)gcc
AS          = $(TOOLCHAIN)$(TCHAIN_PREFIX)gcc
LINK        = $(TOOLCHAIN)$(TCHAIN_PREFIX)ld
NM          = $(TOOLCHAIN)$(TCHAIN_PREFIX)nm
AR          = $(TOOLCHAIN)$(TCHAIN_PREFIX)ar
LOAD        = $(TOOLCHAIN)$(TCHAIN_PREFIX)objcopy
SIZE    	= $(TOOLCHAIN)$(TCHAIN_PREFIX)size
OBJDUMP    	= $(TOOLCHAIN)$(TCHAIN_PREFIX)objdump

LINK_SCT        = config/config.lds
#头文件路径列表
INCLUDES        =   -I$(ROOT)                               \
                    -I$(SDKROOT)/config/storage_media_cfg/nand \
                    -I./include              \
                    -I./drv/debug_uart              \
                    -I../boot1/include              \
                    -I../boot1/include/interinc     \
					-I../boot1/include/arch   \
                    -I../boot1/include/block_device
#编译器参数  -march=armv7-a -mfloat-abi=hard -mfpu=neon
CFLAGS      = -O1 -s -mcpu=cortex-a8 $(INCLUDES)
CXXFLAGS    =
#汇编器参数
ASFLAGS     = -mcpu=cortex-a8
#C库

LIBS		= $(TOOLCHAIN)/lib/gcc/arm-linux-gnueabihf/4.9.4/libgcc.a
#链接器参数
LKFLAGS    := -s -O2 $(LKFLAGS) -T$(LINK_SCT) -nostartfiles -Map=boot0.map
#链接器参数
ARFLAGS     = -r
#加载器参数
LDFLAGS     =

#定义生成的目标文件(输出/本地)
TMPTARGET   = boot0_origin.bin
LOCALTARGET 	= boot0_nand.elf



#从所有子目录中得到源代码的列表
SRCCS= \
    Boot0_C_part.c \
    Boot0_head.c \
        drv/debug_uart/debug_uart.c \
        drv/debug_uart/uart_hd.c \
        drv/debug_uart/format_transformed.c \
        drv/init_dram/dram_sun4i.c \
        drv/init_dram/dram_helpers.c \
        drv/init_dram/dram_sun4i_auto.c \
		sys_op/mmu/mmu.c \
		lib/service/service.c \
		lib/service/pin_service.c \
		lib/check_sum/check.c \
		lib/misc/misc.c \
		../boot1/misc/div/div0.c \
		../boot1/misc/mem.c \
	    load_Boot1_from_nand/load_Boot1_from_nand.c \
		load_Boot1_from_nand/nand/basic_nf_read.c \
		load_Boot1_from_nand/nand/adv_NF_read.c \
		load_Boot1_from_nand/nfc_for_boot0/src/nand_scan_for_boot.c \
		load_Boot1_from_nand/nfc_for_boot0/src/nand_simple_for_boot0.c \
		load_Boot1_from_nand/nfc_for_boot0/src/nfc_for_boot0.c \
		load_Boot1_from_nand/nand_for_boot0/osal/nand_osal_boot0.c \
		load_Boot1_from_nand/nand_for_boot0/nand_for_boot0.c
        # drv/sunxi_nand.c

SRCSS= \
    boot0_start.S \
	sys_op/mmu/mmu_asm.S \
	sys_op/cache/cache.S


#得到源代码对应的目标文件的列表
OBJS=$(SRCCS:.c=.o) $(SRCSS:.S=.o)

.PHONY:all clean version build size dump

# Default target.
all: version $(TMPTARGET) size

# Display compiler version information.
version :
	# @echo $(COBJ)
	# @echo $(CSRC)
	@$(CC) --version
# Display size of file.
size:
	@echo
	$(SIZE) -B $(LOCALTARGET)

#生成输出目标文件  -S -g -R .note -R .comment
$(TMPTARGET):$(LOCALTARGET)
	$(LOAD) $(LDFLAGS) -O binary $(LOCALTARGET) $(TMPTARGET)
	$(NM) $(LOCALTARGET) > system.map
	-$(WORKTOOLS)/update_checksum/genchecksum_uboot $(TMPTARGET) boot0.bin
	@echo ----------------------------
	@echo target make finish
	@echo ----------------------------

#生成本地目标文件
$(LOCALTARGET):$(OBJS)
	$(LINK) $(LKFLAGS) -o $@ $(filter %.o ,$+) $(LIBS)

# Compile: create object files from C source files. ARM or Thumb(-2)
%.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

%.o: %.S
	$(CC) -c $(CFLAGS) $< -o $@

dump:
	$(OBJDUMP) -D -b binary -m arm boot0.bin > boot0.bin.asm

# 删除生成的中间文件
clean:
	-rm $(OBJS) $(LOCALTARGET) $(TMPTARGET)
